//
// Created by Scave on 2025/8/28.
//

#include "UpdateBroadcastSystem.h"
#include "component/EventComponents.h"
#include "scene/Scene.h"

NS_RIDER_BEGIN

    void UpdateBroadcastSystem::configure(EntityManager& entities, EventManager& events) {

    }

    void UpdateBroadcastSystem::update(EntityManager& entities, EventManager& events, TimeDelta dt) {
        for (auto entity: entities.entities_with_components<SceneEventComponent>()) {
            auto component = entity.component<SceneEventComponent>();
            if (component->on_update) {
                component->on_update();
            }
        }
    }

    void UpdateBroadcastSystem::receive(const SceneUpdatedEvent& event) {
        for (auto entity: event.scene->GetEntityManager().entities_with_components<SceneEventComponent>()) {
            auto component = entity.component<SceneEventComponent>();
            if (component->on_last_update) {
                component->on_last_update();
            }
        }
    }

NS_RIDER_END